import { _decorator, Color, color, Component, Label, Node, tween, v3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Tips')
export class Tips extends Component {
    
    text:Label
    tipsStr:string = ""
    tipsColor:Color = color(0,0,0)

    protected start(): void {
        this.text = this.node.getComponentInChildren(Label)
        this.updateLable()
    }


    protected onEnable(): void {
        tween(this.node).by(1.5,{position:v3(0,250,0)},{easing:"quartOut"}).call(()=>{
            this.node.removeFromParent()
        }).start()
    }

    setInfoText(str:string){
        this.tipsStr = str
        this.tipsColor.set(0,0,0)
        this.updateLable()
    }
    setErrorText(str:string){
        this.tipsStr = str
        this.tipsColor.set(255,0,0)
        this.updateLable()
    }
    setSuccessText(str:string){
        this.tipsStr = str
        this.tipsColor.set(0,255,0)
        this.updateLable()
    }

    updateLable(){
        if(this.text==null){
            return
        }
        this.text.string = this.tipsStr
        this.text.color = this.tipsColor
    }
}


